package com.mediacloud.app.newsmodule.activity.microlive.x

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.ForegroundColorSpan
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.mediacloud.app.newsmodule.R

class IMCommentAdapter(val context: Context) : RecyclerView.Adapter<IMCommentHolder>() {
   var nameColor =Color.parseColor("#999999")
    var data: MutableList<IMCommentData> = ArrayList()
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): IMCommentHolder {

        return IMCommentHolder(LayoutInflater.from(context).inflate(R.layout.x_microlive_im_comment_item, parent, false))
    }

    override fun getItemCount(): Int {
        return data.size
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: IMCommentHolder, position: Int) {
        val d = data[position]
        val spannableStringBuilder = SpannableStringBuilder(d.name + "：" + d.content)
        spannableStringBuilder.setSpan(ForegroundColorSpan(nameColor),0,d.name.length+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
        (holder.itemView as TextView).text = spannableStringBuilder
    }
}